package mclight.indicators;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import mclight.containers.Container;
import mclight.Style;
import mclight.ValueComponent;

class ProgressBar extends ValueComponent
{
	public function new(?parent:DisplayObjectContainer, ?container:Container, xpos:Float = 0, ypos:Float = 0)
	{
		super(parent, container, xpos, ypos);
	}
	
	override function init():Void
	{
		super.init();
		setSize(100, 10);
	}
	
	var _back:Sprite;
	
	var _bar:Sprite;
	
	override function construct():Void
	{
		_back = new Sprite();
		_back.filters = [getComponentShadow(2, true)];
		_sprite.addChild(_back);
		
		_bar = new Sprite();
		_bar.x = 1;
		_bar.y = 1;
		_bar.filters = [getComponentShadow(1)];
		_sprite.addChild(_bar);
	}
	
	override function updateValueView():Void
	{
		var scale = (_value - _minValue) / (_maxValue - _minValue);
		_bar.scaleX = Math.isNaN(scale) || scale < 0 ? 0 : scale;
	}
	
	// PUBLIC METHODS
	
	public override function draw():Void
	{
		super.draw();
		var g = _back.graphics;
		g.clear();
		g.beginFill(Style.BACKGROUND);
		g.drawRect(0, 0, _width, _height);
		g.endFill();
		
		var g = _bar.graphics;
		g.clear();
		g.beginFill(Style.PROGRESS_BAR);
		g.drawRect(0, 0, _width - 2, _height - 2);
		_bar.scaleX = 0;
		_bar.graphics.endFill();
	}
	
	// HANDLERS
	
	// PROPERTIES
}
